#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/22 15:00
    Desc  :
--------------------------------------
"""
from servers.models.HeadersModel import Headers
from servers.servers.BaseServices import BaseServices


class HeaderServices(BaseServices):

    def __init__(self, document = Headers):
        super(HeaderServices, self).__init__(document)

    def get_headers_dict(self, **kwargs):

        headers = Headers.objects(**kwargs)
        data = {}
        if headers.count() != 0:
            for i in headers:
                data.update(i.headerDict())
            return data


def set_headers_by_value(**kwargs):
    """
    通过请求头名称设置请求头
    :return:
    """
    projectId = kwargs.get('projectId')
    headers = Headers.objects(projectId = projectId)

    return headers


def get_headers_dict(**kwargs):

    headers = Headers.objects(**kwargs)
    data = {}
    if headers.count() != 0:
        for i in headers:
            data.update(i.headerDict())

        return data